import {request} from "@umijs/max";
import * as API from "@/services";
import {ForgetResetPasswd, SendVerificationCode, UserEmailOrMobileChange, UserRegister} from "@/services";

/**
 * 密码修改
 */
export async function modifyPwd(dto: API.ModifyPwd): Promise<API.RespResult<boolean>> {
  return request(`/api/v1/modify-pwd`, {
    method: 'POST',
    data: dto,
  });
}

export async function modifyExpiredPwd(dto: API.ModifyExpiredPwd): Promise<API.RespResult<boolean>> {
  return request(`/api/v1/modify-expired-pwd`, {
    method: 'POST',
    data: dto,
  });
}

/**
 * 注册
 */
export async function register(data: UserRegister, opts?: API.AxiosRequestOpts) {
  return request<API.RespResult<boolean>>('/api/v1/front/auth/register', {
    method: 'PUT',
    data,
    ...(opts || {}),
  });
}

/**
 * 忘记密码
 */
export async function forgot(data: ForgetResetPasswd, opts?: API.AxiosRequestOpts) {
  return request<API.RespResult<boolean>>('/api/v1/front/auth/forgot', {
    method: 'POST',
    data,
    ...(opts || {}),
  });
}

/**
 * 变更手机
 */
export async function changePhone(data: UserEmailOrMobileChange, opts?: API.AxiosRequestOpts) {
  return request<API.RespResult<boolean>>('/api/v1/front/auth/change-phone', {
    method: 'POST',
    data,
    ...(opts || {}),
  });
}

/**
 * 变更邮箱
 */
export async function changeEmail(data: UserEmailOrMobileChange, opts?: API.AxiosRequestOpts) {
  return request<API.RespResult<boolean>>('/api/v1/front/auth/change-email', {
    method: 'POST',
    data,
    ...(opts || {}),
  });
}


/**
 * 发送(短信|邮箱)验证码
 */
export async function sendVerificationCode(data: SendVerificationCode, opts?: API.AxiosRequestOpts) {
  return request<API.RespResult<boolean | string>>('/api/v1/send-verification-code', {
    method: 'POST',
    data,
    ...(opts || {}),
  });
}

